Don't recreate adopt instance in every render#12
Don't recreate adopt instance in every render#12pedronauck merged 2 commits intopedronauck:masterfrom
Conversation
|
I think the failing test Eg.: If you pass <Adopt
passedToggleValue={dynamicValue} // this should works reactively
mapper={{
toggle: ({ passedToggleValue }) => <Toggle foo={passedToggleValue} />,
value: <Value />
}}
/>
{({ toggle, value }) => (
// here my logic uses toggle and value props
)}
</Adopt>But you will never dynamically add some third new component (change |
|
Also, just a off-topic tip: you can reduce your lib size just refactoring this thing to - const propsWithoutRest = omit(keys(rest), props)
+ const propsWithoutRest = { children }You will always know what the props are outside the rest (because you pick it statically). And this: - return <Component {...omit(['mapper', 'children'], props)}>{props.children}</Component>
+ const { mapper, ...rest } = props
+ return <Component {...rest} />You don't need to remove So you can remove this omit utility. |
|
That's a good point @renatorib! I didn't think this way, but really, this make a lot of sense ✌️ |
Fix #11
This change create a
adopt()instance at constructor, so it will never change. It's like creating it outside (it really does the same thing).